package com.example.myutil;

import java.io.IOException;
import java.io.InputStream;
import java.net.CookiePolicy;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.params.ClientPNames;
import org.apache.http.cookie.Cookie;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;

public class ClientManager {
	private static HttpClient httpclient = HttpClientBuilder.create().build();

	public static HttpClient getHttpClient() {
		if (httpclient != null) {
			return httpclient;
		}
		return null;
	}

	public static HttpPost getHttpPost(String url) {
		HttpPost post = new HttpPost(url);
		return post;
	}

	public static HttpGet getHttpGet(String url) {
		HttpGet get = new HttpGet(url);
		return get;
	}

	public static HttpResponse getResponse(HttpPost post) throws ClientProtocolException, IOException {
		return httpclient.execute(post);
	}

	public static HttpResponse getResponse(HttpGet get) throws ClientProtocolException, IOException {
		return httpclient.execute(get);
	}

	public static InputStream getStream(HttpResponse response) throws IllegalStateException, IOException {
		HttpEntity httpEntity = response.getEntity();
		InputStream is = httpEntity.getContent();
		return is;
	}
}
